<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>分配服务单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="resources/css/public.css" media="all" />
</head>
<body class="childrenBody">

<!--给用户分配角色的弹出层-->
<div style="padding: 10px;"  id="selectUserRoleDiv">
    <h3  id="servDueToo2" class="layui-bg-green" align="center"></h3>
    <table class="layui-hide" id="userTable" lay-filter="userTable"></table>
    <input type="hidden" id="IdHiden"></input>
    <input type="hidden" id="servDueToo"></input>


    <div align="center"><button type="button" class="layui-btn" id="assigUserBtn" >分配员工</button></div>
</div>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script th:inline="none">
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;
            var servNo=$("#IdHiden").val();
            var servDueToo=$("#servDueToo").val();
            if(servDueToo!="" && servDueToo!=null){
                $("#servDueToo2").text("已分配员工："+servDueToo);
            }else{
                $("#servDueToo2").text("暂未分配");
            }
        //员工列表
        var tableIns = table.render({
            elem: '#userTable',
            url : 'users/service',
            page : false,
            id : "userListTable",
            cols : [[
                {type: "checkbox", fixed:"left"},
                {field: 'realname', title: '员工名', align:"center"}
            ]]
        });

        //重新分配
        $("#assigUserBtn").click(function () {
            var checkStatus = table.checkStatus('userListTable');
            var data = checkStatus.data;
            var username = [];

            if(data.length>1){
                layer.msg("只能输入一个！");
                setTimeout(function(){
                    window.location= "toDistributeService.do";
                },1000);
            }
            if(data.length < 2 && data.length>0) {
                for (var i in data) {
                    username.push(data[i].realname);
                }
            $.ajax({
                type:"GET",
                url:"/services/distribute.do",
                data:{servNo:servNo,username:username[0]},
                success:function (res) {
                    if(res.code=1401){
                        var index1=parent.layer.getFrameIndex(window.name)
                        parent.layer.close(index1);
                        layer.msg(res.msg);
                        parent.location.reload();
                    }else if(res.code=-1401){
                        layer.msg(res.msg);
                    }
                }

            });}
        });

    })

</script>
</body>
</html>